package com.clkj.cldisabledmanclient.mvp.myasset;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.clkj.cldisabledmanclient.R;
import com.clkj.cldisabledmanclient.adapter.jaylv.JayLvBaseAdapter;
import com.clkj.cldisabledmanclient.base.BaseFragment;
import com.clkj.cldisabledmanclient.bean.MyAssetBean;
import com.clkj.cldisabledmanclient.util.LogUtil;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2017/6/20.
 */

public class FragmentMyOriginAsset extends BaseFragment {


    //默认的是isFirstVisibles true ,刚进来的时候分两种情况
    //1.如果切过来的时候 setVisibleHint在OnCreate之前调用，那isFirstVisible为true，这个时候不进行任何操作；
    //等方法执行到onActivityCreated的时候，在执行一次setUserVisibleHint 这个时候把默认的是isFirstVisibles 设为false
    //然后这个时候调用setUserVISIBLEhINT为true  去获取数据
    //2.如果是后面再次切过来，那isFirstVisible已经为false，那就可以直接通过setUserVisibleHint获取数据了

    //代表这个界面是不是第一次被使用
    boolean isFirstUsed = true;
    boolean isGetData = false;
    //是否显示过子fragment
    boolean isShowSonFragment = false;

    public static final String NEWSKIND = "newstype";
    Integer mPageIndex;
    boolean isRefresh;
    boolean canLoad;


    private List<MyAssetBean> myAssetBeanList = new ArrayList<>();
    private JayLvBaseAdapter<MyAssetBean> mAdpter;


    private ListView mLvNews;
    private RelativeLayout mRlEmpty;
    private Context mContext;


    public static FragmentMyOriginAsset newInstance() {
        Bundle bundle = new Bundle();
        //bundle.putSerializable(NEWSKIND, newsType);
        FragmentMyOriginAsset fragment = new FragmentMyOriginAsset();
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            //mNewsType = (NewsTypeBean) bundle.getSerializable(NEWSKIND);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my_origin_assets, container, false);
        initData();
        assignView(view);
        initView();

        //tvContent.setText(newsType);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //fragment 可见的情况下 进行加载数据。不可见则不加载
        if (getUserVisibleHint()) {
            if (isFirstUsed) {
                isFirstUsed = false;
                setUserVisibleHint(true);
            }
            //不可见，说明fragment已经初始话完成,就直接把isFirstVisible改为false 再次切过来的时候就直接可以加载数据了
        } else {
            isFirstUsed = false;
        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        // LogUtil.e("CartVisible");
        if (getUserVisibleHint()) {
            LogUtil.e("MyShuoShuoVisible");
            //如果不是firstvisible才去进行下面的操作  因为第一次很可能出现各种问题
            if (!isFirstUsed) {
                if (!isGetData) {
                    getOriginData();
                }
            }
        } else {
            LogUtil.e("faXianFragmentVisible");
        }
    }

    @Override
    public void initData() {
        mPageIndex = 1;
        canLoad = true;
        mContext = getActivity();
    }

    //获取初始数据
    void getOriginData() {


    }


    @Override
    public void assignView(View view) {


    }

    @Override
    public void initView() {


    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        mContext = null;
    }
}
